package core.units;
import java.awt.Point;

import core.*;
import core.actions.*;
import core.units.*;
import core.weapons.*;

public class ArtilleryBuggy extends Unit{
	
	private int rotateMultiplier = 1;
	private int recentX=0, recentY=0;
	private int checkCounter = 2;
	
	public ArtilleryBuggy(Point inPoint, Player m){
		super(inPoint.x,inPoint.y, m);
		health=40;
		maxHealth=40;
		speed=350;
		recentX = x;
		recentY = y;
	}
	/*public void autoFire(){
		attackTimer++;
		if(attackTimer>=150){
			
			main.attacks.add(new Bullet(x, y, master, angleTo(findNearestEnemy()), 25, 9000, 0.01, 500000));
			attackTimer=0;
		}
	}*/
	public void ai(){
		tX=0;
		tY=0;
		double dx, dy, range;
		int targetId=findNearestEnemy();
		dx=main.units.get(targetId).getX()-x;
		dy=main.units.get(targetId).getY()-y;
		range=Math.sqrt(dx*dx+dy*dy);
		if(range>300000)	
			dir=angleTo(targetId)+0.2*rotateMultiplier;
		else if(range<100000)
			dir=angleTo(targetId)+0.3*rotateMultiplier;
		else
			dir=angleTo(targetId)+0.25*rotateMultiplier;
		
		checkCounter--;
		if(checkCounter == 0){
			checkCounter = 10;
			recheckDirection();
		}
		
		
	}
	private void recheckDirection(){
		if(Math.abs(recentX-x) < speed*checkCounter/5 && Math.abs(recentY-y) < speed*checkCounter/5){
			rotateMultiplier = rotateMultiplier*-1;
		}
		recentX = x;
		recentY = y;
	}
	
}
